﻿
namespace UserDefinedForms.Windows.Forms
{
	/// <summary>
	/// abstract FormData typed datagridview
	/// </summary>
	[System.ComponentModel.DesignerCategoryAttribute("code")]
	public abstract class FormDataDataGridViewBase : System.Windows.Forms.UserControl
	{	
		/// <summary> 
		/// Thrown when the current Entity changed.
		/// </summary>
		public event System.EventHandler<FormDataDataGridViewEventArgs> CurrentEntityChanged;
		
		#region Fields
				
		/// <summary> 
		/// the current entity.
		/// </summary>
		private Entities.FormData _currentFormData = null;
		//private Dictionary<string, string> _columnsHeaders = new Dictionary<string, string>();
		
		/// <summary> 
		/// the datagridview instance
		/// </summary>
		protected System.Windows.Forms.DataGridView uxFormDataDataGridView;
		
		/// <summary> 
		/// the errorprovider
		/// </summary>
		protected System.Windows.Forms.ErrorProvider uxFormDataErrorProvider;
		
		/// <summary> 
		/// the bindingsource
		/// </summary>
		protected System.Windows.Forms.BindingSource uxFormDataBindingSource;
		
		
		/// <summary> 
		/// the DGV column associated with the DataId property
		/// </summary>
		protected System.Windows.Forms.DataGridViewTextBoxColumn uxDataIdDataGridViewColumn;
		/// <summary> 
		/// the DGV column associated with the Code property
		/// </summary>
		protected System.Windows.Forms.DataGridViewComboBoxColumn uxCodeDataGridViewColumn;
		/// <summary> 
		/// the DGV column associated with the FormId property
		/// </summary>
		protected System.Windows.Forms.DataGridViewComboBoxColumn uxFormIdDataGridViewColumn;
		/// <summary> 
		/// the DGV column associated with the ControlId property
		/// </summary>
		protected System.Windows.Forms.DataGridViewComboBoxColumn uxControlIdDataGridViewColumn;
		
		/// <summary> 
		/// the DGV column associated with the Data property
		/// </summary>
		protected System.Windows.Forms.DataGridViewTextBoxColumn uxDataDataGridViewColumn;
		/// <summary> 
		/// the DGV column associated with the SupOrderCode property
		/// </summary>
		protected System.Windows.Forms.DataGridViewComboBoxColumn uxSupOrderCodeDataGridViewColumn;
		
		/// <summary> 
		/// the DGV column associated with the FormType property
		/// </summary>
		protected System.Windows.Forms.DataGridViewTextBoxColumn uxFormTypeDataGridViewColumn;
		
		#endregion
					
		#region Combo list
		
				
		private Entities.TList<Entities.Order> _CodeList;
		
		/// <summary> 
		/// The list of selectable Order
		/// </summary>
		[System.ComponentModel.Category("DropDownList BindingSources")]
		public Entities.TList<Entities.Order> CodeList
		{
			get {return this._CodeList;}
			set 
			{
				this._CodeList = value;
				this.uxCodeDataGridViewColumn.DataSource = null;
				this.uxCodeDataGridViewColumn.DataSource = this._CodeList;
			}
		}
		
		private bool _allowNewItemInCodeList;
		
		/// <summary> 
		/// Indicates if user can add an item in the list of Order
		/// </summary>
		[System.ComponentModel.Category(".netTiers"), System.ComponentModel.Description("Indicates if end user can add a new item in the combobox. an event will be thrown then.")]
		public bool AllowNewItemInCodeList
		{
			get { return _allowNewItemInCodeList;}
			set
			{
				this._allowNewItemInCodeList = value;
				this.uxCodeDataGridViewColumn.DisplayStyle = value ? System.Windows.Forms.DataGridViewComboBoxDisplayStyle.ComboBox : System.Windows.Forms.DataGridViewComboBoxDisplayStyle.DropDownButton;
			}
		}
		
				
		private Entities.TList<Entities.FormControl> _ControlIdList;
		
		/// <summary> 
		/// The list of selectable FormControl
		/// </summary>
		[System.ComponentModel.Category("DropDownList BindingSources")]
		public Entities.TList<Entities.FormControl> ControlIdList
		{
			get {return this._ControlIdList;}
			set 
			{
				this._ControlIdList = value;
				this.uxControlIdDataGridViewColumn.DataSource = null;
				this.uxControlIdDataGridViewColumn.DataSource = this._ControlIdList;
			}
		}
		
		private bool _allowNewItemInControlIdList;
		
		/// <summary> 
		/// Indicates if user can add an item in the list of FormControl
		/// </summary>
		[System.ComponentModel.Category(".netTiers"), System.ComponentModel.Description("Indicates if end user can add a new item in the combobox. an event will be thrown then.")]
		public bool AllowNewItemInControlIdList
		{
			get { return _allowNewItemInControlIdList;}
			set
			{
				this._allowNewItemInControlIdList = value;
				this.uxControlIdDataGridViewColumn.DisplayStyle = value ? System.Windows.Forms.DataGridViewComboBoxDisplayStyle.ComboBox : System.Windows.Forms.DataGridViewComboBoxDisplayStyle.DropDownButton;
			}
		}
		
				
		private Entities.TList<Entities.DesignForm> _FormIdList;
		
		/// <summary> 
		/// The list of selectable DesignForm
		/// </summary>
		[System.ComponentModel.Category("DropDownList BindingSources")]
		public Entities.TList<Entities.DesignForm> FormIdList
		{
			get {return this._FormIdList;}
			set 
			{
				this._FormIdList = value;
				this.uxFormIdDataGridViewColumn.DataSource = null;
				this.uxFormIdDataGridViewColumn.DataSource = this._FormIdList;
			}
		}
		
		private bool _allowNewItemInFormIdList;
		
		/// <summary> 
		/// Indicates if user can add an item in the list of DesignForm
		/// </summary>
		[System.ComponentModel.Category(".netTiers"), System.ComponentModel.Description("Indicates if end user can add a new item in the combobox. an event will be thrown then.")]
		public bool AllowNewItemInFormIdList
		{
			get { return _allowNewItemInFormIdList;}
			set
			{
				this._allowNewItemInFormIdList = value;
				this.uxFormIdDataGridViewColumn.DisplayStyle = value ? System.Windows.Forms.DataGridViewComboBoxDisplayStyle.ComboBox : System.Windows.Forms.DataGridViewComboBoxDisplayStyle.DropDownButton;
			}
		}
		
				
		private Entities.TList<Entities.Order> _SupOrderCodeList;
		
		/// <summary> 
		/// The list of selectable Order
		/// </summary>
		[System.ComponentModel.Category("DropDownList BindingSources")]
		public Entities.TList<Entities.Order> SupOrderCodeList
		{
			get {return this._SupOrderCodeList;}
			set 
			{
				this._SupOrderCodeList = value;
				this.uxSupOrderCodeDataGridViewColumn.DataSource = null;
				this.uxSupOrderCodeDataGridViewColumn.DataSource = this._SupOrderCodeList;
			}
		}
		
		private bool _allowNewItemInSupOrderCodeList;
		
		/// <summary> 
		/// Indicates if user can add an item in the list of Order
		/// </summary>
		[System.ComponentModel.Category(".netTiers"), System.ComponentModel.Description("Indicates if end user can add a new item in the combobox. an event will be thrown then.")]
		public bool AllowNewItemInSupOrderCodeList
		{
			get { return _allowNewItemInSupOrderCodeList;}
			set
			{
				this._allowNewItemInSupOrderCodeList = value;
				this.uxSupOrderCodeDataGridViewColumn.DisplayStyle = value ? System.Windows.Forms.DataGridViewComboBoxDisplayStyle.ComboBox : System.Windows.Forms.DataGridViewComboBoxDisplayStyle.DropDownButton;
			}
		}
		
		#endregion
		
		#region Main Datasource
		
		private Entities.TList<Entities.FormData> _FormDataList;
				
		/// <summary> 
		/// The list of FormData to be displayed in the DGV.
		/// </summary>
		[System.ComponentModel.Category("Data")]
		public Entities.TList<Entities.FormData> FormDataList
		{
			get {return this._FormDataList;}
			set
			{
				this._FormDataList = value;
				this.uxFormDataBindingSource.DataSource = null;
				this.uxFormDataBindingSource.DataSource = value;
				this.uxFormDataDataGridView.DataSource = null;
				this.uxFormDataDataGridView.DataSource = this.uxFormDataBindingSource;				
				//this.uxFormDataBindingSource.ListChanged += new System.ComponentModel.ListChangedEventHandler(uxFormDataBindingSource_ListChanged);
				this.uxFormDataBindingSource.CurrentItemChanged += new System.EventHandler(OnFormDataBindingSourceCurrentItemChanged);
			}
		}
		
		private void OnFormDataBindingSourceCurrentItemChanged(object sender, System.EventArgs e)
		{
			_currentFormData = uxFormDataBindingSource.Current as Entities.FormData;
			
			if (_currentFormData != null)
			{
				_currentFormData.Validate();
			}
			//_FormData.Validate();
			OnCurrentEntityChanged();
		}

		//void uxFormDataBindingSource_ListChanged(object sender, System.ComponentModel.ListChangedEventArgs e)
		//{
			//throw new Exception("The method or operation is not implemented.");
		//}		
		
		#endregion
		
		/// <summary>
		/// Gets the currently selected <see cref="Entities.FormData"/> instance.
		/// </summary>
		public Entities.FormData SelectedFormData
		{
			get {return this._currentFormData;}
		}
		
		#region other properties
		
		/// <summary>
		/// Gets or sets a value indicating whether you have provided your own data-management operations for the DataGridView control.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]
		public bool VirtualMode
		{
			get {return this.uxFormDataDataGridView.VirtualMode;}
			set
			{
				this.uxFormDataDataGridView.VirtualMode = value;
			}
		}
		
		/// <summary>
		/// Gets or sets a value indicating whether the option to add rows is displayed to the user.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]
		public bool AllowUserToAddRows
		{
			get {return this.uxFormDataDataGridView.AllowUserToAddRows;}
			set {this.uxFormDataDataGridView.AllowUserToAddRows = value;}
		}
		
		/// <summary>
		/// Gets or sets a value indicating whether the user is allowed to delete rows from the DataGridView.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]
		public bool AllowUserToDeleteRows
		{
			get {return this.uxFormDataDataGridView.AllowUserToDeleteRows;}
			set {this.uxFormDataDataGridView.AllowUserToDeleteRows = value;}
		}
		
		/// <summary>
		/// Gets the <see cref="DataGridView"/> instance.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]
		public System.Windows.Forms.DataGridView DataGridView
		{
			get {return this.uxFormDataDataGridView;}
		}
		
		/// <summary>
		/// Gets a collection that contains all the columns in the control.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]		
		[System.ComponentModel.DesignerSerializationVisibilityAttribute(System.ComponentModel.DesignerSerializationVisibility.Visible)]
		//[System.ComponentModel.EditorAttribute("System.Windows.Forms.Design.DataGridViewColumnCollectionEditor, System.Design", typeof(System.Drawing.Design.UITypeEditor))] 
		public System.Windows.Forms.DataGridViewColumnCollection Columns
		{
			get { return this.uxFormDataDataGridView.Columns; }
		}
		
		#endregion
		
		/// <summary> 
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.IContainer components = null;
	
		/// <summary> 
		/// Clean up any resources being used.
		/// </summary>
		/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
		protected override void Dispose(bool disposing)
		{
			if (disposing && (components != null))
			{
				components.Dispose();
			}
			base.Dispose(disposing);
		}
	
		#region Constructor
	
		/// <summary>
		/// Initializes a new instance of the <see cref="FormDataDataGridViewBase"/> class.
		/// </summary>
		public FormDataDataGridViewBase()
		{			
			this.components = new System.ComponentModel.Container();			
			
			this.uxFormDataDataGridView = new System.Windows.Forms.DataGridView();
			this.uxFormDataBindingSource = new System.Windows.Forms.BindingSource(this.components);
			this.uxFormDataErrorProvider = new System.Windows.Forms.ErrorProvider(this.components);
			this.uxDataIdDataGridViewColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
			this.uxCodeDataGridViewColumn = new System.Windows.Forms.DataGridViewComboBoxColumn();
			this.uxFormIdDataGridViewColumn = new System.Windows.Forms.DataGridViewComboBoxColumn();
			this.uxControlIdDataGridViewColumn = new System.Windows.Forms.DataGridViewComboBoxColumn();
			this.uxDataDataGridViewColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
			this.uxSupOrderCodeDataGridViewColumn = new System.Windows.Forms.DataGridViewComboBoxColumn();
			this.uxFormTypeDataGridViewColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
			//this.uxCodeBindingSource = new OrderBindingSource(this.components);
			//((System.ComponentModel.ISupportInitialize)(this.uxCodeBindingSource)).BeginInit();
			//this.uxControlIdBindingSource = new FormControlBindingSource(this.components);
			//((System.ComponentModel.ISupportInitialize)(this.uxControlIdBindingSource)).BeginInit();
			//this.uxFormIdBindingSource = new DesignFormBindingSource(this.components);
			//((System.ComponentModel.ISupportInitialize)(this.uxFormIdBindingSource)).BeginInit();
			//this.uxSupOrderCodeBindingSource = new OrderBindingSource(this.components);
			//((System.ComponentModel.ISupportInitialize)(this.uxSupOrderCodeBindingSource)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.uxFormDataDataGridView)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.uxFormDataBindingSource)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.uxFormDataErrorProvider)).BeginInit();
			this.SuspendLayout();
						
			// 
			// uxFormDataErrorProvider
			// 
			this.uxFormDataErrorProvider.ContainerControl = this;
			this.uxFormDataErrorProvider.DataSource = this.uxFormDataBindingSource;						
			// 
			// uxFormDataDataGridView
			// 
			this.uxFormDataDataGridView.AutoGenerateColumns = false;
			this.uxFormDataDataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
			this.uxFormDataDataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
		this.uxDataIdDataGridViewColumn,
		this.uxCodeDataGridViewColumn,
		this.uxFormIdDataGridViewColumn,
		this.uxControlIdDataGridViewColumn,
		this.uxDataDataGridViewColumn,
		this.uxSupOrderCodeDataGridViewColumn,
		this.uxFormTypeDataGridViewColumn			});
			this.uxFormDataDataGridView.Dock = System.Windows.Forms.DockStyle.Fill;
			this.uxFormDataDataGridView.Location = new System.Drawing.Point(0, 0);
			this.uxFormDataDataGridView.Name = "uxFormDataDataGridView";
			this.uxFormDataDataGridView.Size = new System.Drawing.Size(470, 300);
			this.uxFormDataDataGridView.TabIndex = 0;	
			this.uxFormDataDataGridView.BackgroundColor = System.Drawing.Color.WhiteSmoke;
			this.uxFormDataDataGridView.EnableHeadersVisualStyles = false;
			this.uxFormDataDataGridView.DataError += new System.Windows.Forms.DataGridViewDataErrorEventHandler(this.OnFormDataDataGridViewDataError);
			this.uxFormDataDataGridView.CellValueNeeded += new System.Windows.Forms.DataGridViewCellValueEventHandler(this.OnFormDataDataGridViewCellValueNeeded);
			this.uxFormDataDataGridView.CellValuePushed += new System.Windows.Forms.DataGridViewCellValueEventHandler(this.OnFormDataDataGridViewCellValuePushed);
			
			//
			// uxDataIdDataGridViewColumn
			//
			this.uxDataIdDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxDataIdDataGridViewColumn.DataPropertyName = "DataId";
			this.uxDataIdDataGridViewColumn.HeaderText = "DataId";
			this.uxDataIdDataGridViewColumn.Name = "uxDataIdDataGridViewColumn";
			this.uxDataIdDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxDataIdDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxDataIdDataGridViewColumn.ReadOnly = true;		
			//
			// uxCodeDataGridViewColumn
			//
			this.uxCodeDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxCodeDataGridViewColumn.DataPropertyName = "Code";
			this.uxCodeDataGridViewColumn.HeaderText = "Code";
			this.uxCodeDataGridViewColumn.Name = "uxCodeDataGridViewColumn";
			this.uxCodeDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxCodeDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxCodeDataGridViewColumn.ReadOnly = false;		
			//
			// uxFormIdDataGridViewColumn
			//
			this.uxFormIdDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxFormIdDataGridViewColumn.DataPropertyName = "FormId";
			this.uxFormIdDataGridViewColumn.HeaderText = "FormId";
			this.uxFormIdDataGridViewColumn.Name = "uxFormIdDataGridViewColumn";
			this.uxFormIdDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxFormIdDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxFormIdDataGridViewColumn.ReadOnly = false;		
			//
			// uxControlIdDataGridViewColumn
			//
			this.uxControlIdDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxControlIdDataGridViewColumn.DataPropertyName = "ControlId";
			this.uxControlIdDataGridViewColumn.HeaderText = "ControlId";
			this.uxControlIdDataGridViewColumn.Name = "uxControlIdDataGridViewColumn";
			this.uxControlIdDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxControlIdDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxControlIdDataGridViewColumn.ReadOnly = false;		
			//
			// uxDataDataGridViewColumn
			//
			this.uxDataDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxDataDataGridViewColumn.DataPropertyName = "Data";
			this.uxDataDataGridViewColumn.HeaderText = "Data";
			this.uxDataDataGridViewColumn.Name = "uxDataDataGridViewColumn";
			this.uxDataDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxDataDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxDataDataGridViewColumn.ReadOnly = false;		
			//
			// uxSupOrderCodeDataGridViewColumn
			//
			this.uxSupOrderCodeDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxSupOrderCodeDataGridViewColumn.DataPropertyName = "SupOrderCode";
			this.uxSupOrderCodeDataGridViewColumn.HeaderText = "SupOrderCode";
			this.uxSupOrderCodeDataGridViewColumn.Name = "uxSupOrderCodeDataGridViewColumn";
			this.uxSupOrderCodeDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxSupOrderCodeDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxSupOrderCodeDataGridViewColumn.ReadOnly = false;		
			//
			// uxFormTypeDataGridViewColumn
			//
			this.uxFormTypeDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxFormTypeDataGridViewColumn.DataPropertyName = "FormType";
			this.uxFormTypeDataGridViewColumn.HeaderText = "FormType";
			this.uxFormTypeDataGridViewColumn.Name = "uxFormTypeDataGridViewColumn";
			this.uxFormTypeDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxFormTypeDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxFormTypeDataGridViewColumn.ReadOnly = false;		
			//
			// uxCodeDataGridViewColumn
			//				
			this.uxCodeDataGridViewColumn.DisplayMember = "OrderType";	
			this.uxCodeDataGridViewColumn.ValueMember = "OrderId";	
			this.uxCodeDataGridViewColumn.DisplayStyleForCurrentCellOnly = true;
			//uxCodeDataGridViewColumn.DataSource = uxCodeBindingSource;				
				
			//
			// uxControlIdDataGridViewColumn
			//				
			this.uxControlIdDataGridViewColumn.DisplayMember = "Name";	
			this.uxControlIdDataGridViewColumn.ValueMember = "ControlId";	
			this.uxControlIdDataGridViewColumn.DisplayStyleForCurrentCellOnly = true;
			//uxControlIdDataGridViewColumn.DataSource = uxControlIdBindingSource;				
				
			//
			// uxFormIdDataGridViewColumn
			//				
			this.uxFormIdDataGridViewColumn.DisplayMember = "Name";	
			this.uxFormIdDataGridViewColumn.ValueMember = "FormId";	
			this.uxFormIdDataGridViewColumn.DisplayStyleForCurrentCellOnly = true;
			//uxFormIdDataGridViewColumn.DataSource = uxFormIdBindingSource;				
				
			//
			// uxSupOrderCodeDataGridViewColumn
			//				
			this.uxSupOrderCodeDataGridViewColumn.DisplayMember = "OrderType";	
			this.uxSupOrderCodeDataGridViewColumn.ValueMember = "OrderId";	
			this.uxSupOrderCodeDataGridViewColumn.DisplayStyleForCurrentCellOnly = true;
			//uxSupOrderCodeDataGridViewColumn.DataSource = uxSupOrderCodeBindingSource;				
				
			
			// this
			this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
			this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
			this.Controls.Add(this.uxFormDataDataGridView);
			this.Name = "FormDataDataGridView";
			this.Size = new System.Drawing.Size(470, 300);
			//((System.ComponentModel.ISupportInitialize)(this.uxCodeBindingSource)).EndInit();
			//((System.ComponentModel.ISupportInitialize)(this.uxControlIdBindingSource)).EndInit();
			//((System.ComponentModel.ISupportInitialize)(this.uxFormIdBindingSource)).EndInit();
			//((System.ComponentModel.ISupportInitialize)(this.uxSupOrderCodeBindingSource)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.uxFormDataErrorProvider)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.uxFormDataDataGridView)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.uxFormDataBindingSource)).EndInit();
			this.ResumeLayout(false);
		}
		#endregion
				
		#region events
		
		/// <summary>
		/// Raised the CurrentEntityChanged event.
		/// </summary>
		protected void OnCurrentEntityChanged()
		{
			if (CurrentEntityChanged != null)
			{
				FormDataDataGridViewEventArgs args = new FormDataDataGridViewEventArgs();
				args.FormData = _currentFormData;
				CurrentEntityChanged(this, args); 
			}
		}
		
		#endregion
		
		/// <summary>
		/// Strongly typed event 
		/// </summary>
		public class FormDataDataGridViewEventArgs : System.EventArgs
		{
			private Entities.FormData	_FormData;
	
			/// <summary>
			/// the  Entities.FormData instance.
			/// </summary>
			public Entities.FormData FormData
			{
				get { return _FormData; }
				set { _FormData = value; }
			}	
		}
		
		/// <summary>
		/// Handles the DataError event of the uxFormDataDataGridView control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="T:System.Windows.Forms.DataGridViewDataErrorEventArgs"/> instance containing the event data.</param>
		protected void OnFormDataDataGridViewDataError(object sender, System.Windows.Forms.DataGridViewDataErrorEventArgs e)
		{
			System.Diagnostics.Debug.WriteLine(string.Format( "{0}, {1}", e.ColumnIndex, e.RowIndex));
		}
		
		/// <summary>
		/// Handles the CellValueNeeded event of the uxFormDataDataGridView control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="T:System.Windows.Forms.DataGridViewCellValueEventArgs"/> instance containing the event data.</param>
		protected void OnFormDataDataGridViewCellValueNeeded(object sender, System.Windows.Forms.DataGridViewCellValueEventArgs e)
		{
			switch(uxFormDataDataGridView.Columns[e.ColumnIndex].Name)
			{
					case "uxDataIdDataGridViewColumn":
						e.Value = FormDataList[e.RowIndex].DataId;
						break;
					case "uxCodeDataGridViewColumn":
						e.Value = FormDataList[e.RowIndex].Code;
						break;
					case "uxFormIdDataGridViewColumn":
						e.Value = FormDataList[e.RowIndex].FormId;
						break;
					case "uxControlIdDataGridViewColumn":
						e.Value = FormDataList[e.RowIndex].ControlId;
						break;
					case "uxDataDataGridViewColumn":
						e.Value = FormDataList[e.RowIndex].Data;
						break;
					case "uxSupOrderCodeDataGridViewColumn":
						e.Value = FormDataList[e.RowIndex].SupOrderCode;
						break;
					case "uxFormTypeDataGridViewColumn":
						e.Value = FormDataList[e.RowIndex].FormType;
						break;
				default:
				break;
			}
		}
		
		/// <summary>
		/// Handles the CellValuePushed event of the uxFormDataDataGridView control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="T:System.Windows.Forms.DataGridViewCellValueEventArgs"/> instance containing the event data.</param>
		protected void OnFormDataDataGridViewCellValuePushed(object sender, System.Windows.Forms.DataGridViewCellValueEventArgs e)
		{
			switch(uxFormDataDataGridView.Columns[e.ColumnIndex].Name)
			{
					case "uxDataIdDataGridViewColumn":
						FormDataList[e.RowIndex].DataId = (System.Int32)e.Value;
						break;
					case "uxCodeDataGridViewColumn":
						FormDataList[e.RowIndex].Code = (System.Int32)e.Value;
						break;
					case "uxFormIdDataGridViewColumn":
						FormDataList[e.RowIndex].FormId = (System.Int32)e.Value;
						break;
					case "uxControlIdDataGridViewColumn":
						FormDataList[e.RowIndex].ControlId = (System.Int32)e.Value;
						break;
					case "uxDataDataGridViewColumn":
						FormDataList[e.RowIndex].Data = (System.String)e.Value;
						break;
					case "uxSupOrderCodeDataGridViewColumn":
						FormDataList[e.RowIndex].SupOrderCode = (System.Int32?)e.Value;
						break;
					case "uxFormTypeDataGridViewColumn":
						FormDataList[e.RowIndex].FormType = (System.Int32)e.Value;
						break;
				default:
				break;
			}
		}
	}
}
